﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.ZZT
{
    /// <summary>
    /// Used for locations that are stored in the stack.
    /// </summary>
    class LocationValue : ILocation
    {
        protected int x;
        protected int y;

        public LocationValue()
        {
            X = 0;
            Y = 0;
        }

        public LocationValue(int x, int y)
        {
            X = x;
            Y = y;
        }

        public override string ToString()
        {
            return "[" + x.ToString() + "," + y.ToString() + "]";
        }

        public ILocation Add(ILocation other)
        {
            return new LocationValue(x + other.X, y + other.Y);
        }

        public ILocation Add(IVector vector)
        {
            return new LocationValue(x + vector.X, y + vector.Y);
        }

        public ILocation Subtract(ILocation other)
        {
            return new LocationValue(x - other.X, y - other.Y);
        }

        public ILocation Subtract(IVector vector)
        {
            return new LocationValue(x - vector.X, y - vector.Y);
        }

        public int X
        {
            get
            {
                return x;
            }
            set
            {
                x = (value & 0xFF);
            }
        }

        public int Y
        {
            get
            {
                return y;
            }
            set
            {
                y = (value & 0xFF);
            }
        }
    }
}
